﻿using Ninject;
using Ninject.Modules;

namespace WindowsGame.IoC
{
	/// <summary>
	/// IoCContainer will resolve/release all applicable object references.
	/// </summary>
	public static class IoCContainer
	{
		private static IKernel kernel;

		public static T Resolve<T>()
		{
			if (null == kernel)
			{
				INinjectModule staticModule = new StaticModule();
				INinjectModule dynamicModule = new DynamicModule();

				INinjectModule[] modules = new[] { staticModule, dynamicModule };
				kernel = new StandardKernel(modules);
			}

			return kernel.Get<T>();
		}

		public static void Release()
		{
			if (null == kernel)
			{
				return;
			}

			kernel.Dispose();
			kernel = null;
		}
	}
}